package controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import service.army_service;
import entity.army;
import entity.user;

public class score_army_servlet extends HttpServlet{
	private static final long serialVersionUID = 1L;
	private army_service am_service=new army_service();
	public score_army_servlet() {
		super();
	}
	public void destroy() {
		super.destroy(); 
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		HttpSession session= request.getSession();
		String requestURI = request.getRequestURI();
		user u=(user)session.getAttribute("user");
		String userAgent = request.getHeader("User-Agent");
		boolean is_mobile = false;
		String[] mobileKeywords = {"Android", "iPhone", "iPad", "Windows Phone"};
		for (String keyword : mobileKeywords) {
		    if (userAgent.contains(keyword)) {
		    	is_mobile = true;
		        break;
		    }
		}
		request.setAttribute("is_mobile", is_mobile);
		if (requestURI.equals("/teamfight_wiki/score_army_msg")){
			int score=Integer.parseInt(request.getParameter("score"));
			int army_id=Integer.parseInt(request.getParameter("id"));
			if (u==null || u.getType()!=3){
				request.getRequestDispatcher("/account_manage/login.jsp").forward(request,response);
				return;
			}
			am_service.score(score,army_id);
			request.getRequestDispatcher("/all_army").forward(request,response);
		}

	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}
}
